import { request } from "@/utils/request";

const BASE = "/movies"

export interface Movie {
    id: string;
    img: string;
    title: string;
}

export const getListOneAPI = (id: string) => {
    return request.get({ url: `${BASE}/${id}` });
};

// json-server 有 bug，分页不能设置 _limit 参数，一旦设置则分页失效，只会返回第一页的前 limit 数据
export const getListAPI = (page: number = 1, pageSize: number = 10, isPageable: boolean = true) => {
    return request.get({ url: `${BASE}`, params: isPageable ? { _page: page} : {} });
};

export const getAllListAPI = () => {
    return request.get({ url: `${BASE}` });
};

export const addListAPI = (data: Partial<Movie>) => {
    return request.post({
        url: `${BASE}`,
        data: { ...data }
    });
};

export const updateListOneAPI = (data: Partial<Movie>) => {
    return request.put({ url: `${BASE}/${data.id}`, data });
};

export const deleteListOneAPI = (id: string) => {
    return request.delete({ url: `${BASE}/${id}` });
};

export const getListOneDetailAPI = (id: string) => {
    return request.get({ url: `${BASE.slice(0, -1)}Detail/?listId=${id}` });
};